package friend

import (
	"context"
	"im_sys/apps/social/rpc/socialclient"
	"im_sys/pkg/ctxdata"

	"im_sys/apps/social/api/internal/svc"
	"im_sys/apps/social/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type FriendPutInListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 好友申请列表
func NewFriendPutInListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FriendPutInListLogic {
	return &FriendPutInListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *FriendPutInListLogic) FriendPutInList(req *types.FriendPutInListReq) (resp *types.FriendPutInListResp, err error) {
	// todo: add your logic here and delete this line
	uid := ctxdata.GetUid(l.ctx)

	friendPutIn, err := l.svcCtx.FriendPutInList(l.ctx, &socialclient.FriendPutInListReq{
		UserId: uid,
	})
	if err != nil {
		return &types.FriendPutInListResp{}, err
	}

	respList := make([]*types.FriendRequests, 0, len(friendPutIn.List))
	for _, v := range friendPutIn.List {
		f := &types.FriendRequests{
			Id:           int64(v.Id),
			UserId:       v.UserId,
			ReqUid:       v.ReqUid,
			ReqMsg:       v.ReqMsg,
			ReqTime:      v.ReqTime,
			HandleResult: int(v.HandleResult),
		}
		respList = append(respList, f)
	}
	return &types.FriendPutInListResp{
		List: respList,
	}, nil
}
